#include "DealerTurn.h"

DealerTurn::DealerTurn(Dealer *dealer)
{
	nbPartieAvantNouvelleDistribution = dealer->nbPartieAvantNouvelleDistribution;
	compteurDePartie = dealer->compteurDePartie;
	isDistribute = dealer->isDistribute;
	cards = dealer->cards;
	playerMemory = dealer->playerMemory;
	//Comme c'est un remplacement je supprime l'objet passé en paramètre
	delete dealer;
}
DealerTurn::DealerTurn() {
	nbPartieAvantNouvelleDistribution = NBGAME;
	compteurDePartie = nbPartieAvantNouvelleDistribution;
	isDistribute=true;
}
void DealerTurn::distribution(Player & player1, Player & player2)
{
	// si partie qui nécciste une distribution ou si les cartes n'ont pas encore était distribué
	if(DISTRIBUTE_IDEM_FLOP || compteurDePartie == nbPartieAvantNouvelleDistribution || Game::getGame()->gameinfo.getBoardCards()[3].getNumero() == -1 )
	{
		cout << "------------------------------------------------------" << endl;
		cout << "------------Start DealerTurn::distribution-----------" << endl;
		// 4ème carte flop /
		int v1 = (rand()%(Game::getGame()->cards.size()-1))+1;
		int b1=1;
		for( map <int,Card>::iterator ii=Game::getGame()->cards.begin(); ii!=Game::getGame()->cards.end(); ++ii)
		{
			if(b1==v1)
			{
				Card c =(Card)(*ii).second;
				Game::getGame()->gameinfo.setBoardCards(3, c);
				Game::getGame()->cards.erase(ii);
				cout << "card choisi : "<< c.toString().toStdString() << endl;
				break;
			} else b1++;
		}

		//sauvegarde joueurs
		playerMemory[1] = player1;
		playerMemory[2] = player2;
		cout << "------------Finish DealerTurn::distribution-----------" << endl;
		cout << "-------------------------------------------------------" << endl;
	}
}
